package org.third.security.jaas;

import java.security.Principal;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public final class EmailPrincipal implements Principal {

    private String name;

    public EmailPrincipal(String name) {
        this.name = "Email-" + name;
    }

    public String getName() {
        return name;
    }

    public boolean equals(Object o) {
        return (o instanceof EmailPrincipal) && this.name.equalsIgnoreCase(((EmailPrincipal) o).name);
    }

    public int hashCode() {
        return name.toUpperCase().hashCode();
    }

    /**
     * Gets the value of user attribute of this principal
     * 
     * @param key attribute name returned from {@link #getAttributeNames()}
     * @return attribute values set
     */
    public Set<String> getAttributeValues(String key){
        return userAttributes.get(key);
        
    }

    /**
     * Gets the list of attributes of this principal
     * 
     * @return attribute list
     */
    public Collection<String> getAttributeNames(){
        return userAttributes.keySet();
        
    }

    static Map<String, Set<String>> userAttributes = new ConcurrentHashMap<String, Set<String>>();

    static{
        Set<String> addressValue  = new HashSet<String>();
        addressValue.add("shaghai");
        userAttributes.put("address", addressValue);
        
        Set<String> mobileValues  = new HashSet<String>();
        mobileValues.add("533444");
        userAttributes.put("mobile", mobileValues);
        
        Set<String> groupValues  = new HashSet<String>();
        groupValues.add("Admin");
        groupValues.add("SuperAdmin");
        groupValues.add("UserManager");
        userAttributes.put("group", groupValues);
    }
}